package com.brush.brushcommon.utils;

import lombok.extern.log4j.Log4j2;

import java.security.MessageDigest;

@Log4j2(topic = "business")
public class Md5 {

    public static String getMD5(byte[] source) {
        String s = null;
        char hexDigits[] = {'0', '1', '2', '3','4','5','6','7','8','9','a','b','c','d','e','f'};
        try {
            MessageDigest md = md = MessageDigest.getInstance("MD5");
            md.update(source);
            byte tmp[] = md.digest();
            char str[] = new char[16 * 2];
            int k = 0;
            for(int i = 0; i < 16; i++) {
                byte byte0 = tmp[i];
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            s = new String(str);
        } catch (Exception e) {
            log.error("catch Exception",e);
        }
        return s;
    }

    public static void main(String[] args) {
        String s = getMD5("123456".getBytes());
        System.out.println(s);
    }

}